package toolkit;

import java.util.HashMap;

public class MultiCounter
{
	protected final HashMap<Object, Counter> map = new HashMap<Object, Counter>();

	public HashMap<Object, Counter> getMap()
	{
		return map;
	}
	
	public Counter get(Object key)
	{
		Counter counter = map.get(key);

		if (counter == null)
		{
			counter = new Counter();

			map.put(key, counter);
		}

		return counter;
	}

	public void increment(Object key)
	{
		increment(key, 1);
	}

	public void increment(Object key, int delta)
	{
		get(key).increment(delta);
	}

	public void decrement(Object key)
	{
		decrement(key, 1);
	}

	public void decrement(Object key, int delta)
	{
		get(key).decrement(delta);
	}

	public long count(Object key)
	{
		return get(key).count();
	}
}
